package com.whj.servicepay.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Auther: wanghaijun
 * @Date: 2023/3/1 - 03 - 01 - 9:09 
 * @Description: com.whj.servicepay.controller
 */

@Data
@Component
//可用读取配置文件的值
@ConfigurationProperties(prefix = "alipay")
public class AlipayConfig {
    private String appId;
    private String appPrivateKey;
    private String publicKey;
    private String notifyUrl;

    //启动时初始化
    @PostConstruct
    public void init() {
        Config config = new Config();
        //基础配置
        config.protocol = "https";
        config.gatewayHost = "openapi.alipaydev.com";
        config.signType = "RSA2";
        //业务配置
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.publicKey;
        config.notifyUrl = this.notifyUrl;
        //应用配置
        Factory.setOptions(config);
    }
}
